<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/include/taglib.jsp"%>
<html>
	<head>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="format-detection" content="telephone=no">
		<meta charset="UTF-8">
		<title>债权项目_共富网_Gofull.com.cn</title>
		<script src="/v3/js/jquery-1.10.2.min.js" type="text/javascript"></script>		
		<script src="/v3/js/wybScroll.js" type="text/javascript"></script>		
		<script src="/v3/js/startMove.js" type="text/javascript"></script>	
		<link type="text/css" rel="stylesheet" href="/v3/css/wstyle.css">
		<link type="text/css" rel="stylesheet" href="/v3/css/account.css">
		<script type="text/javascript" src="/v3/js/showts.js"></script>
	</head>
	<body>
		<div id="wrap">
			<ul class="proItem">
				<s:if test="#request.yebMap.productStatus == 1">
				<li onclick="location.href='/loanYebDetailInvest.do?pid=${yebMap.pid }'">
					余额宝
					<span class="proRate">${yebAnnualRate }%</span>
				</li>
				</s:if>
				<s:else>
				<li class="disable">
					余额宝
					<span class="proRate">已售完</span>
				</li>
				</s:else>
				<s:if test="#request.ylbMap.productStatus == 1">
				<li onclick="location.href='/loanYlbDetailInvest.do?pid=${ylbMap.pid }'">
					月利宝
					<span class="proRate">${ylbMap.productAnnualRate }%</span>
				</li>
				</s:if>
				<s:else>
				<li class="disable">
					月利宝
					<span class="proRate">已售完</span>
				</li>
				</s:else>
				<s:if test="#request.jfbMap.productStatus == 1">
				<li onclick="location.href='/loanJfbDetailInvest.do?pid=${jfbMap.pid }'">
					季发宝
					<span class="proRate">${jfbMap.productAnnualRate }%</span>
				</li>
				</s:if>
				<s:else>
				<li class="disable">
					季发宝
					<span class="proRate">已售完</span>
				</li>
				</s:else>
				<s:if test="#request.wybMap.borrowStatus != 2">
				<li class="disable">
					稳盈宝
					<span class="proRate">已售完</span>
				</li>
				</s:if>
				<s:else>
				<li onclick="location.href='/loanWybDetailInvest.do'">
					稳盈宝
					<span class="proRate">${wybMap.annualRate }%</span>
				</li>
				</s:else>
			</ul>
			<div class="itemInfo">
				<p class="itemTo">年化收益率</p>
				<img src="/v3/images/circle_bg2.png"/>
				<ul id="text_list">
					<s:if test="#request.debtlist.size>0">
					<s:iterator value="#request.debtlist" var="debt" status="st" >
					<li>
						<div <s:if test="#st.index==0"> class="infoShow" </s:if> >
							<p class="itemRate" id="q_hieght">${debt.realAnnualRate }%</p>
							<p class="itemIf"><a href="/wchatDebtDetail.do?id=${debt.id }">查看详情>></a></p>
						</div>
					</li>
					</s:iterator>
				</s:if>
				</ul>
			</div>
			<s:if test="#request.debtlist.size>0">
				<s:iterator value="#request.debtlist" var="debt" status="st" >
					<div name="investSum"  <s:if test="#st.index!=0"> style="display:none " </s:if> class="reMoney">可售金额：￥${debt.debtSum}</div>
					<s:if test="#st.index==0"> <input type="hidden" id="debtSum" value="${debt.debtSum}"> </s:if>
				</s:iterator>
			</s:if>
			<div class="limit_box" id="limit_box">
			<div id="ico_list">
				<a href="javascript:void(0)" id="btn_prev" class="btn_scroll"><i id="icon-prev" class="icon-prev"></i></a>
				<a href="javascript:void(0)" id="btn_next" class="btn_scroll showBtn"><i id="icon-next" class="icon-next"></i></a>
				<div class="limit_con">
				<ul style="left: 0px;">
					<s:if test="#request.debtlist.size>0">
					<s:iterator value="#request.debtlist" var="debt" status="st" >
					<li <s:if test="#st.index==0"> class="active" </s:if> ><a href="javascript:void(0)" data="${debt.id}" investSum="${debt.debtSum}" ><i <s:if test="#debt.isDayThe==2"> class="icon-Day" </s:if> <s:else> class="icon-${debt.deadline - debt.hasDeadline }M"</s:else> ></i><s:if test="#debt.isDayThe==2"> ${debt.deadline - debt.hasDeadline }天 </s:if> <s:else> ${debt.deadline - debt.hasDeadline }个月 </s:else></a></li>
					</s:iterator>
				</s:if>
				</ul>
				</div>
			</div>	
			</div>
			<div class="money-input">
				<div class="login_input inv_input_none">
				<div class="r_line">
				<i class="icon-inMoneyNo"></i>
				</div>
				<input type="hidden" id="realnameFlag" value="${session.user.isBindIdNo}">
				<div class="in_put"><input readonly="readonly" placeholder="debt" id="inputAmount" name="inputAmount" maxlength="17" type="tel"></div>
				</div>
				<div class="box-bottom"><img src="/v3/images/box_icon2.jpg"/></div>
			</div>
			<div class="Nxt-btn"><a href="javascript:buyCredit();" id="investBt">确认购买</a></div>
			<p class="inv-note">每个工作日&nbsp;10:00、14:00、17:00&nbsp;更新总额度</p>
		</div>
		<jsp:include page="/include/v3/footer.jsp"></jsp:include>
	</body>
	<script type="text/javascript">	
	var product = {
			remain : '$("#debtSum").val()',
			id : $(".active a").attr("data"),
			usableSum : ${accmountStatisMap.usableSum},
			sta : 2
		};
	var usableSum = '${accmountStatisMap.usableSum}';
	$(function(){
	  $('#agreeContract').click(function(){
	    if ($('#agreeContract').attr("checked") == "checked") {
	      $('#agreeContract').removeAttr("checked");
	    } else {
	      $('#agreeContract').attr("checked", "checked");
	    }
	  });
	  $('#novice-chk').click(function(){
		    if ($('#novice-chk').attr("checked") == "checked") {
		      $('#novice-chk').removeAttr("checked");
		    } else {
		      $('#novice-chk').attr("checked", "checked");
		    }
	 }); 
	});

	
	//购买债权
	function buyCredit() {
	  var user = '${session.user}';
	  var loanInvestorId = product.id;
	  var soldPrice = product.remain;
	  var userCash = product.usableSum;
	 /** var forbidStatus = Number(${debtDetailMap.debtStatus});**/
	  var errorTip = $('#errorTip');

	  if (user == null || user == '') {
	    window.location.href="/wchatLoginInit.do";
	    return;
	  };
	  if(userCash < soldPrice){
		  showAlert('您的余额不足，请充值');
	    return;
	  };
	  var param = {};
	  param['paramMap.debtId'] = loanInvestorId;
	  param["paramMap.pageId"] = "debtWchatInvest";
	 /** param["paramMap.code"] = authCode;**/
	  $.ajax({
	    dataType: 'json',
	    url: '/buyCredit.do',
	    type: 'POST',
	    data: param,
	    beforeSend:function() {
	    },
	    success:function(data) {
	    	if(data.msg == '验证码错误') {
	    		showAlert('验证码错误');
	            switchCode();
	        }else if(data.msg == "success"){
          	  window.location.href="/investSuccess.do";
	        //window.location.href="/wchatDebtDetail.do?id="+loanInvestorId;
	      }else{
	    	  showAlert(data.msg);
	      }
	    },
	    error: function() {
	      showAlert("购买失败，请刷新页面或稍后再试");
	    }
	  });
	}
	
	</script>
</html>
